import 'package:client_flutter_door/model/door_model.dart';
import 'package:client_flutter_door/vars.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';

class Log {
  static setLog(value) async {
    final key = DateFormat('yyyy-MM-dd').format(DateTime.now()); //日期：2024-01-18
    final pref = await Vars.prefes;
    var data = pref.getStringList(key);
    data ??= [];
    data.add(value + DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.now()));
    await pref.setStringList(key, data);
    await Provider.of<DoorModel>(Vars.navigatorKey.currentContext!,
            listen: false)
        .getLogs();
  }

  static Future<List<String>> getLogs() async {
    final key = DateFormat('yyyy-MM-dd').format(DateTime.now()); //日期：2024-01-18
    final pref = await Vars.prefes;
    var data = pref.getStringList(key);
    data ??= [];
    final reversedData=data.reversed;
    return reversedData.toList();
  }
}
